$db = $.couch.db("ahora_no");
function retrieve_and_print( data ) {
    var msg = '<ul>';
    var listos = new Array;
    for (var i in data.rows ) {
	var result = 0;
	msg += "<li>"+data.rows[i].id + " - " ;
	for ( var k in data.rows[i].doc.vector ) {
	    result += data.rows[i].doc.vector[k];
	}
	msg += result + "</li>";
	data.rows[i].doc.result = result;
	listos.push( data.rows[i].doc );
    }
    msg += "</ul>"
    $("#profile").html(msg);
    $db.bulkSave( { "docs": listos}, 
		  { success: function(data) {
			$("#content").html("<p> Enviados correctamente " +
					   data.length + " objetos </p>");
					  },
		    error: function(status) {
			$("#content").html("<p> Anda que ya nos vale " +
					   status + " </p>");
		    }} );
}

$(function() {   
    $("#account").couchLogin({
        loggedIn : function(r) {
	    $db.view('cm/by', { success: retrieve_and_print,
				limit: 8,
				key: "1",
				include_docs: 'true'
			      })
	},
        loggedOut : function() {
            $("#profile").html('<p>No estás conectado, quiyo.</p>');
        }
    });
 });